<?php
namespace Shop\Model;
use Think\Model;

class ShopProgressModel extends Model {

	protected $tableName = 'shop_progress';
	protected $_validate = array(
		array('status','0','请填写进度状态',1,'notequal'),
		array('order_id','/[0-9]\d*/','订单id参数错误',Model::MUST_VALIDATE),

	);
	protected $_auto = array(
		array('create_time', NOW_TIME, self::MODEL_INSERT),
	);

	public function progress_list($option){	//获取列表
		if (!empty($option['order_id'])){
			$where_arr[] = 'order_id = ' . $option['order_id'];
		}

		$where_arr[] = 'is_del = 0';

		$where_str = '';
		if (!empty($where_arr)){
			$where_str .=  implode(' and ', $where_arr);
		}
		$ret['list']  = $this->where($where_str)->order('create_time desc')->page($option['page'], $option['r'])->select();
		$ret['count'] = $this->where($where_str)->count();
		return $ret;
	}

	public function progress_by_id($id){	//按id获取进度信息
		$ret = $this->where('id ='.$id)->find();
		return $ret;
	}

	public function edit_progress($data){		//新增或编辑进度信息
		if (empty($data['id'])){
			$ret = $this->add($data);
		}else{
			$ret = $this->where('id='.$data['id'])->save($data);
		}
		return $ret;
	}

	public function del_progress($data){		//删除进度信息
		if (!empty($data['ids'])){
			$ret = $this->where('id in (' . $data['ids'] . ')')->save($data);
		}
		return $ret;
	}

}

